from django.shortcuts import render

# Create your views here.
from rest_framework.generics import ListAPIView
from .models import Banner
from luffyapi.settings import constants
from .serializers import BannerListModelSerializer
class BannerListAPIView(ListAPIView):
    queryset = Banner.objects.filter(is_show=True, is_delete=False).order_by("orders","-id")[:constants.HOME_BANNER_LENGTH]
    serializer_class = BannerListModelSerializer

from .models import Nav
from .serializers import NavModelSerializer
class HeaderNavListAPIView(ListAPIView):
    queryset = Nav.objects.filter(is_show=True, is_delete=False, position=0).order_by("orders","-id")[:constants.HOME_HEADER_LENGTH]
    serializer_class = NavModelSerializer

class FooterNavListAPIView(ListAPIView):
    queryset = Nav.objects.filter(is_show=True, is_delete=False, position=1).order_by("orders","-id")[:constants.HOME_FOOTER_LENGTH]
    serializer_class = NavModelSerializer


from rest_framework.views import APIView
from rest_framework.response import Response
from redis import Redis
class RedisDemoAPI(APIView):
    """演示python操作redis，这里不涉及项目的代码"""
    def get(self,request):
        redis_conn = Redis(host='127.0.0.1', port=6379, db=3)
        # # 设置一个字符串name，值为xiaolan
        # redis_conn.set("name","xiaolan")
        # # 获取一个字符串
        # name = redis_conn.get("name")
        # print(name) # b'xiaolan'
        # print(name.decode()) # xiaolan
        # # 设置一个hash数据
        # redis_conn.hset("team","laoda","liubei")
        # 查询一个数据的类型
        # print( redis_conn.type("team") ) # b'hash'
        # # 获取hash的所有键值对
        # print( redis_conn.hgetall("team") ) # {b'laoda': b'liubei'}
        # # 删除一个指定键的数据，del在python是关键字，所以改名为 delete
        # redis_conn.delete("name")

        return Response("ok")
